package company;

import java.util.*;

public class DelDerectory {
    public static void main(String[] args) {
        // 输入
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        if (n == 1) {
            System.out.println("NA");
        }
        TreeSet<Integer> set = new TreeSet<>();
        Map<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            int node = scanner.nextInt();
            int parent = scanner.nextInt();
            map.put(node,parent);
            set.add(node);
            set.add(parent);
        }

        int delId = scanner.nextInt();
        set.remove(delId);
        dfs(set, map, delId);
        Iterator<Integer> iterator = set.iterator();
        StringBuffer sb = new StringBuffer();
        while(iterator.hasNext()) {
            sb.append(iterator.next()).append(" ");
        }
        if (set.size() == 1) {
            System.out.println("NA");
        } else {
            System.out.println(sb.substring(1,sb.length()-1));
        }
    }
    public static void dfs(Set<Integer> set, Map<Integer,Integer> map, int parentId) {
        for (Integer key: map.keySet()) {
            if (parentId ==  map.get(key)) {
                set.remove(key);
                dfs(set, map,key);
            }
        }
    }
}
